package cn.iocoder.yudao.module.system.api.role;

import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.api.role.dto.UserRoleDTO;
import cn.iocoder.yudao.module.system.dal.dataobject.permission.UserRoleDO;
import cn.iocoder.yudao.module.system.dal.mysql.permission.UserRoleMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserRoleApiImpl implements UserRoleApi{
    @Resource
    private UserRoleMapper userRoleMapper;

    @Override
    public int insertUserRole(UserRoleDTO userRole) {

        return userRoleMapper.insert(BeanUtils.toBean(userRole, UserRoleDO.class));
    }

    @Override
    public int updateUserRole(UserRoleDTO userRole) {
        return userRoleMapper.updateById(BeanUtils.toBean(userRole, UserRoleDO.class));
    }

    @Override
    public List<UserRoleDTO> selectUserRole(Long id) {
        LambdaQueryWrapper<UserRoleDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserRoleDO ::getUserId, id );
        List<UserRoleDO> roleDOS = userRoleMapper.selectList(queryWrapper);
        return BeanUtils.toBean(roleDOS, UserRoleDTO.class);
    }
}
